package 剑指offer;

public class _57和为s的两个数字 {
    public int[] twoSum(int[] nums, int target) {
        int i = 0, j = nums.length - 1;
        int[] res = new int[2];
        while (i < j){
            int sum = nums[i] + nums[j];
            if(sum > target){
                j--;
            }else if(sum < target){
                i++;
            }else{
                res[0] = nums[i];
                res[1] = nums[j];
                break;
            }
        }
        return res;
    }
}
